﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace client.app.gui2
{
    /// <summary>
    /// RadioButton1.xaml 的交互逻辑
    /// </summary>
    public partial class RadioButton1 : UserControl, IUInput
    {
        public event RoutedEventHandler Checked;

        public bool StopEvent
        {
            get { return true; }
        }
        public string Text
        {
            get { return tbText.Text; }
            set
            {
                tbText.Text = value;
                this.UpBeginDraw();
            }
        }
        public bool IsChecked
        {
            get { return radioButton.IsChecked == true; }
            set
            {
                radioButton.IsChecked = value;
                this.UpBeginDraw();
            }
        }
        public string GroupName
        {
            get { return radioButton.GroupName; }
            set { radioButton.GroupName = value; }
        }

        public RadioButton1()
        {
            InitializeComponent();

            radioButton.Checked += new RoutedEventHandler(radioButton_Checked);
            radioButton.Unchecked += new RoutedEventHandler(radioButton_Unchecked);
            MouseLeftButtonDown += new MouseButtonEventHandler(RadioButton1_MouseLeftButtonDown);
            IsEnabledChanged += new DependencyPropertyChangedEventHandler(RadioButton1_IsEnabledChanged);
        }

        void RadioButton1_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Opacity = IsEnabled ? 1 : .3;
        }
        void RadioButton1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (radioButton.IsChecked != true)
            {
                radioButton.IsChecked = true;
            }
        }
        void radioButton_Checked(object sender, RoutedEventArgs e)
        {
            brDot.Visibility = Visibility.Visible;
            if (Checked != null)
            {
                Checked(this, new RoutedEventArgs());
            }
            this.UpBeginDraw();
        }
        void radioButton_Unchecked(object sender, RoutedEventArgs e)
        {
            brDot.Visibility = Visibility.Collapsed;
            if (Checked != null)
            {
                Checked(this, new RoutedEventArgs());
            }
            this.UpBeginDraw();
        }

        public void CallMouseEvent(MouseEventType type, Point point)
        {
            if (type == MouseEventType.LEFT_DOWN)
            {
                if (radioButton.IsChecked != true)
                {
                    radioButton.IsChecked = true;

                    if (Checked != null)
                    {
                        Checked(this, new RoutedEventArgs());
                    }
                }
            }
        }
    }
}
